#include <iostream>
using std::cout;
using std::endl;

class A
{
public:
    //声明纯虚函数
    virtual void print() const = 0;
    virtual void display() const = 0;
};

class B
: public A
{
public:
    void print() const override{
        cout << "B::print()" << endl;
    }

    void display() const override{
        cout << "B::display()" << endl;
    }
};

class C
: public A
{
public:
    void print() const override{
        cout << "C::print()" << endl;
    }
};

class D
: public C
{
public:
    void print() const override{
        cout << "D::print()" << endl;
    }
    void display() const override{
        cout << "D::display()" << endl;
    }
};

void test1(){
    /* C c; */
    D d;
    A * pa = &d;
    pa->print();
    pa->display();

    B b;
    pa = &b;
    pa->print();
    pa->display();

}



#if 0
void test0(){
    /* A a; */
    B b;
    A * pa = &b;
    pa->print();

    C c;
    pa = &c;
    pa->print();

    A & ref = b;
    ref.print();

    A & ref2 = c;
    ref2.print();
}
#endif

int main(void){
    test1();
    return 0;
}
